package com.supply.supplymanage.controller;

import com.github.pagehelper.PageInfo;
import com.supply.supplymanage.biz.BuyerBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 15119 on 2018-10-15.
 */
@Controller
@RequestMapping("/buyer")
public class BuyerController {
    @Autowired
    private BuyerBiz buyurBiz;

    @RequestMapping("/getAll")
    @ResponseBody
    public PageInfo getAll(@RequestParam("pageNum") Integer pageNum, @RequestParam("buycode") String buycode){

        PageInfo pageInfo=buyurBiz.getAll(pageNum,buycode);

        return pageInfo;
    }

    @RequestMapping("/getBuyer")
    @ResponseBody
    public PageInfo getBuyer(@RequestParam("pageNum") Integer pageNum, @RequestParam("purcode") String purcode){

        PageInfo pageInfo=buyurBiz.getBuyer(pageNum,purcode);

        return pageInfo;
    }

    @RequestMapping("/getCaiwu")
    @ResponseBody
    public PageInfo getCaiwu(@RequestParam("pageNum") Integer pageNum, @RequestParam("purcode") String purcode){

        PageInfo pageInfo=buyurBiz.getCaiwu(pageNum,purcode);

        return pageInfo;
    }

    @RequestMapping("/update/{arr}")
    @ResponseBody
    public String update(@PathVariable("arr") String  arr){
        System.out.println(arr);

        String[] arrstr=arr.split(",");


        buyurBiz.update(arrstr);
        return "redirect:/getAll.action";


    }


    @RequestMapping("/updateBuyer/{arr}")
    @ResponseBody
    public String updateBuyer(@PathVariable("arr") String  arr){
        System.out.println(arr);

        String[] arrstr=arr.split(",");


        buyurBiz.updateBuyer(arrstr);
        return "redirect:/getAll.action";


    }
    @RequestMapping("/updateCaiwu/{arr}")
    @ResponseBody
    public String updateCaiwu(@PathVariable("arr") String  arr){
        System.out.println(arr);

        String[] arrstr=arr.split(",");


        buyurBiz.updateCaiwu(arrstr);
        return "redirect:/getAll.action";


    }
}
